<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Batch Properties</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/select2.min.css">
    <link rel="stylesheet" href="../css/select2-bootstrap4.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        html,
        body {
            height: 100%;
        }
        .container2 {
            padding: 10px;
            display: block;
            overflow: hidden;
        }
        @media (min-width: 375px) {
            .filedlabel {
                width: 100%;
                max-width: 9.6rem;
                font-size: 1rem;
            }
        }

    </style>
</head>
<body>
    <div id="app">
        <div class="container2">
            <form>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Batch']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="text" :disabled="statusData.Part_AttBatch == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttBatch === 'M'?lan['Mandatory']:(statusData.Part_AttBatch === 'T' ? lan['Tracked']:'')"  class="form-control form-control-theme" v-model="searchdata.batch">
                            </div>
                        </div>  
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Manufacturing_Batch']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="text" :disabled="statusData.Part_AttMfgBatch == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttMfgBatch === 'M'?lan['Mandatory']:(statusData.Part_AttMfgBatch === 'T' ? lan['Tracked']:'')"   class="form-control form-control-theme" v-model="searchdata.mfgBatch">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Production_Batch']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="text" :disabled="statusData.Part_AttMfgLot == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttMfgLot === 'M'?lan['Mandatory']:(statusData.Part_AttMfgLot === 'T' ? lan['Tracked']:'')"   class="form-control form-control-theme" v-model="searchdata.proBatch">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Melt_Number']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="text" :disabled="statusData.Part_AttHeat == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttHeat === 'M'?lan['Mandatory']:(statusData.Part_AttHeat === 'T' ? lan['Tracked']:'')"  class="form-control form-control-theme" v-model="searchdata.meltNumber">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Firmware']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="text"  :disabled="statusData.Part_AttFirmware == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttFirmware === 'M'?lan['Mandatory']:(statusData.Part_AttFirmware === 'T'?lan['Tracked']:'')"  class="form-control form-control-theme" v-model="searchdata.firmware">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Best_Before_Date']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="date" :disabled="statusData.Part_AttBeforeDt == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttBeforeDt === 'M'?lan['Mandatory']:(statusData.Part_AttBeforeDt === 'T'?lan['Tracked']:'')"  class="form-control form-control-theme" v-model="searchdata.beforeDate">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Date_of_Origin']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="date" :disabled="statusData.Part_AttMfgDt == 'N' || btnList.Lot_btn || btnList.attribute_btn" :placeholder="statusData.Part_AttMfgDt === 'M' ? lan['Mandatory']:(statusData.Part_AttMfgDt === 'T' ? lan['Tracked']:'')"   class="form-control form-control-theme" v-model="searchdata.originDate">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Effective_Date']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="date" :disabled="statusData.Part_AttCureDt == 'N' || btnList.Lot_btn || btnList.attribute_btn"  :placeholder="statusData.Part_AttCureDt === 'M' ? lan['Mandatory']:(statusData.Part_AttCureDt === 'T' ? lan['Tracked'] : '')"  class="form-control form-control-theme" v-model="searchdata.effectiveDate">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <div class="d-flex bd-highlight align-items-center">
                            <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Due_Date']}}</div>
                            <div class="p-2 flex-grow-1 bd-highlight">
                                <input type="date" :disabled="statusData.Part_AttExpDt == 'N' || btnList.Lot_btn || btnList.attribute_btn"   :placeholder="statusData.Part_AttExpDt === 'M' ? lan['Mandatory']:(statusData.Part_AttExpDt === 'T' ? lan['Tracked']:'')"  class="form-control form-control-theme" v-model="searchdata.dueDate">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <div class=" row justify-content-center mt-4">
                <div class="col-4 col-md-4">
                    <button type="button" onclick="loadData()" :disabled="confirm_btn" tapmode=""
                        class="btn btn-primary btn-action">{{lan['OK']}}</button>
                </div>


                <div class="col-4 col-md-4">
                    <button type="button" tapmode="" @click="close()"
                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                </div>

            </div>
        </div>

    </div>
    
</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/JsBarcode.all.min.js"></script>
<script type="text/javascript" src="../script/qrcode.min.js"></script>
<script type="text/javascript" src="../script/html2canvas.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/select2/select2.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/createPoBarcode.js"></script>
<script type="text/javascript">
    const app = new Vue({
        el:'#app',
        data:{
            BatchOperate:false,
            searchdata:{
                batch:"",
                mfgBatch:"",
                proBatch:"",
                meltNumber:"",
                firmware:"",
                beforeDate:null,
                originDate:null,
                effectiveDate:null,
                dueDate:null,
                PartNum:'',
                LotNum:"",
                PartLotDescription:""
            },
            item:{},
            type:"",
            btnList:{
            attribute_btn:false,
            Lot_btn:false,
            index:0,
            index1:0,
            Batch_check:false
            },
            statusData:{
                Part_AttBatch: "",
                Part_AttMfgBatch: "",
                Part_AttMfgLot: "",
                Part_AttHeat: "",
                Part_AttFirmware: "",
                Part_AttBeforeDt: "",
                Part_AttMfgDt: "",
                Part_AttCureDt: "",
                Part_AttExpDt: ""
            },
            confirm_btn:false,
        },
       
        method:{

        },
       
        mounted(){

        }
    });
    apiready = function(){
        api.parseTapmode();
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { 
                close()
            }
            // if (ret.type == 'right') { scan(); }

        });
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            close()

        });
       
        server = getapi();
        app.vendors = get_prefs_data("Vendors");
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        
        app.searchdata.name = userinfo.Name;
        app.searchdata.PartNum = api.pageParam.PartNum;
        const PartNum = api.pageParam.PartNum;
        app.searchdata.LotNum = api.pageParam.LotNum;
        app.searchdata.PartLotDescription =api.pageParam.LotNum;
        app.item = api.pageParam.item;
        app.btnList.Lot_btn = api.pageParam.Lot_btn;
        app.type = api.pageParam.type;
        app.btnList.index = api.pageParam.index || 0;
        app.btnList.index1 = api.pageParam.index1 || 0;
        app.btnList.attribute_btn = api.pageParam.attribute_btn
        app.statusData.Part_AttBatch = app.item.Part_AttBatch || "";
        app.statusData.Part_AttMfgBatch = app.item.Part_AttMfgBatch|| "";
        app.statusData.Part_AttMfgLot = app.item.Part_AttMfgLot|| "";
        app.statusData.Part_AttHeat = app.item.Part_AttHeat|| "";
        app.statusData.Part_AttFirmware = app.item.Part_AttFirmware|| "";
        app.statusData.Part_AttBeforeDt = app.item.Part_AttBeforeDt|| "";
        app.statusData.Part_AttMfgDt = app.item.Part_AttMfgDt|| "";
        app.statusData.Part_AttCureDt = app.item.Part_AttCureDt|| "";
        app.statusData.Part_AttExpDt = app.item.Part_AttExpDt|| "";
        console.log(JSON.stringify(api.pageParam.item),333333)
        console.log(JSON.stringify(app.statusData),444444)
        console.log(JSON.stringify(api.pageParam),55555)

        let params = {
            PartNum:api.pageParam.PartNum,
            LotNum:api.pageParam.LotNum
        }
        console.log(JSON.stringify(params),666666)
        PartLotAttribute(params)

    }
    function PartLotAttribute(data){
        let that = this
        api.ajax({
            url: server + 'BaqSvc/WMS_PartLotAttribute/?CompID='+userinfo.Company +'&PartNum='+data.PartNum+'&LotNum='+data.LotNum,
            method:'get',
            returnAll:false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function(ret, err){
            console.log(JSON.stringify(ret),99999)
            if(ret && ret.value.length >0){
                app.searchdata.batch=ret.value[0].PartLot_Batch;
                app.searchdata.mfgBatch=ret.value[0].PartLot_MfgBatch;
                app.searchdata.proBatch=ret.value[0].PartLot_MfgLot;
                app.searchdata.meltNumber=ret.value[0].PartLot_HeatNum;
                app.searchdata.firmware=ret.value[0].PartLot_FirmWare;
                if(ret.value[0].PartLot_BestBeforeDt!=null){
                    app.searchdata.beforeDate=formatted_time(ret.value[0].PartLot_BestBeforeDt); 
                }
                if(ret.value[0].PartLot_MfgDt!=null){
                    app.searchdata.originDate=formatted_time(ret.value[0].PartLot_MfgDt); 
                }
                if(ret.value[0].PartLot_CureDt!=null){
                    app.searchdata.effectiveDate=formatted_time(ret.value[0].PartLot_CureDt); 
                }
                if(ret.value[0].PartLot_ExpirationDate!=null){
                    app.searchdata.dueDate=formatted_time(ret.value[0].PartLot_ExpirationDate) 
                }
            }
        })
    }
    
    function close(){
        api.sendEvent({
            name: 'batch_properties_update',
            extra: app.btnList
        });
        api.closeWin({});


    }
 
    function loadData(){
        if(app.btnList.Lot_btn || app.btnList.attribute_btn){
            close()
            return
        }
        if (Object.keys(app.statusData).every(key => app.statusData[key] === "N")) {
            close_win();
            return
        }
        if(app.statusData.Part_AttBatch == 'M' &&  app.searchdata.batch == ''){
            api.toast({
                msg: lan['Batch'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttMfgBatch == 'M' &&  app.searchdata.mfgBatch == ''){
            api.toast({
                msg: lan['Manufacturing_Batch'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttMfgLot == 'M' &&  app.searchdata.proBatch == ''){
            api.toast({
                msg: lan['Production_Batch'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttHeat == 'M' &&  app.searchdata.meltNumber == ''){
            api.toast({
                msg: lan['Melt_Number'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttFirmware == 'M' &&  app.searchdata.firmware == ''){
            api.toast({
                msg: lan['Firmware'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttBeforeDt == 'M' &&  app.searchdata.beforeDate == ''){
            api.toast({
                msg: lan['Best_Before_Date'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttMfgDt == 'M' &&  app.searchdata.originDate == ''){
            api.toast({
                msg: lan['Date_of_Origin'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        if(app.statusData.Part_AttCureDt == 'M' &&  app.searchdata.effectiveDate == ''){
            api.toast({
                msg: lan['Effective_Date'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }

        if(app.statusData.Part_AttExpDt == 'M' &&  app.searchdata.dueDate == ''){
            api.toast({
                msg: lan['Due_Date'] + lan['Mandatory_Prompt'],
                location: 'middle'
            });
            return
        }
        var model = get_partLot_model1();
        // model.partNum = app.searchdata.PartNum;
        model.ds.PartLot[0].Company = userinfo.Company;
        model.ds.PartLot[0].PartNum = app.searchdata.PartNum;
        model.ds.PartLot[0].LotNum = app.searchdata.LotNum;
        model.ds.PartLot[0].PartLotDescription = app.searchdata.LotNum;
        model.ds.PartLot[0].Batch = app.searchdata.batch;
        model.ds.PartLot[0].MfgBatch = app.searchdata.mfgBatch;
        model.ds.PartLot[0].MfgLot = app.searchdata.proBatch;
        model.ds.PartLot[0].HeatNum = app.searchdata.meltNumber;
        model.ds.PartLot[0].FirmWare = app.searchdata.firmware;
        model.ds.PartLot[0].BestBeforeDt = app.searchdata.beforeDate || null;
        model.ds.PartLot[0].MfgDt = app.searchdata.originDate || null;
        model.ds.PartLot[0].CureDt = app.searchdata.effectiveDate || null;
        model.ds.PartLot[0].ExpirationDate = app.searchdata.dueDate || null;
        model.ds.PartLot[0].RowMod = 'A';
        console.log(JSON.stringify(model), 'UpdateNewPartLot更新');
        api.ajax({
            url: server + 'Erp.BO.LotSelectUpdateSvc/Update',
            method: 'post',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: JSON.stringify(model)
            }
            //data: {values: data1}
        }, function (ret, err) {
            console.log()
            console.log(JSON.stringify(ret),11111)
            console.log(JSON.stringify(err),22222)
           if(ret && ret.parameters != ""){
                // app.BatchOperate = true;
                app.confirm_btn = true
                app.btnList.Lot_btn = false
                app.btnList.attribute_btn = true
                api.setPrefs({
                    key: 'ExpiryDate',
                    value: app.searchdata.dueDate
                });
                if(app.type == "Production"){
                    closeSnWin()
                }else{
                    closeSnWin();
                }
            }else{
                hideProgress();
                errMassage(ret.msg)
            }
        })
        
    };
    function closeSnWin() {
       
        api.sendEvent({
            name: 'batch_properties_update',
            extra: app.btnList
        });
        api.closeWin({});
    }

</script>
</html>